    //
//  THJMyQiuGouDetailVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2017/12/16.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJMyQiuGouDetailVC.h"
#import "ZBNetworking.h"

@interface THJMyQiuGouDetailVC ()
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UILabel *lab3;
@property (weak, nonatomic) IBOutlet UILabel *lab4;
@property (weak, nonatomic) IBOutlet UILabel *lab5;

@end

@implementation THJMyQiuGouDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    [self setGoBackBtn];
    // Do any additional setup after loading the view from its nib.
}
-(void)getData{
    __weak typeof(self) weekself = self;
    NSString * token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
    [MBProgressHUD showMessage:@"" toView:self.view];
    NSString * url;
    if([self.qiugouType isEqual:@"buyer"]){
        url = [NSString stringWithFormat:@"%@index.php?f=buy_6&r=buy_6&m=info&itemid=%@",THJUrlDomain,self.itemid];
    }else{
        url = [NSString stringWithFormat:@"%@index.php?f=buy_6&r=buy_6&m=info&itemid=%@",THJUrlDomain,self.itemid];
    }
    [ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
        request.urlString=url;
        request.apiType=ZBRequestTypeCache;
        [request setValue:token forHeaderField:@"token"];
    }  success:^(id responseObject,apiType type){
        NSDictionary * receiveData = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        [MBProgressHUD hideHUDForView:weekself.view animated:YES];
        if([receiveData[@"status"] isEqual:@"200"]){
            NSString * gg = [THJTools guigeTypeChangeToStrWithType:receiveData[@"data"][@"guige"]];
            self.titleLab.text = receiveData[@"data"][@"title"];
            self.subLab.text = [NSString stringWithFormat:@"种类：%@",receiveData[@"data"][@"catname"]];
             self.subLab2.text = [NSString stringWithFormat:@"采购数量：%@吨",receiveData[@"data"][@"cainum"]];
            self.addtimeLab.text = receiveData[@"data"][@"adddate"];
            self.lab3.text = [NSString stringWithFormat:@"地址：%@",receiveData[@"data"][@"address"]];
            self.lab4.text = [NSString stringWithFormat:@"规格：%@",gg];
            self.lab5.text = [NSString stringWithFormat:@"价格：￥%@吨",receiveData[@"data"][@"price"]];
        }
        NSLog(@"我的求购-%@",receiveData);
    } failed:^(NSError *error){
        [MBProgressHUD hideHUDForView:weekself.view animated:YES];
        NSLog(@"error-%@",error);
    }];
}
- (IBAction)deleteBtnAction:(id)sender {
    if([self.qiugouType isEqual:@"buyer"]){
        __weak typeof(self) weekself = self;
        NSString * token = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
        [MBProgressHUD showMessage:@"" toView:self.view];
        NSString * url = [NSString stringWithFormat:@"%@index.php?f=My_buy_6&r=My_buy_6&m=del&itemid=%@",THJUrlDomain,self.itemid];
        [THJNetWork postDataFromUrl:url parameters:@{@"itemid":self.itemid} Token:token callback:^(NSDictionary* receiveData, NSError *error) {
            [MBProgressHUD hideHUDForView:weekself.view animated:YES];
            [weekself HUDShowMsg:receiveData[@"tip"] AfterDelayDimiss:1];
            if([receiveData[@"status"] isEqual:@"200"]){
                [weekself performSelector:@selector(pop) withObject:nil afterDelay:1];
            }
        }];
    }else{
        [self HUDShowMsg:@"无法删除别人对我的求购" AfterDelayDimiss:1];
    }
    
    
}

@end
